Latest Post

HIGHLIGHTS

Hyundai announces price cuts post GST

Details of price reduction per car are yet to be released

The new-gen Hyundai Verna will be launched next month


overflow-x:scroll;overflow-x:scroll;overflow-x:scroll;overflow-x:scroll;overflow-x:scroll;overflow-x:scroll;overflow-x:scroll;overflow-x:scroll;


Highlight's




Type name ( data type ) variable_name;//this is how you declare variables









[accordion] [item title="C Programming"]
At this time our sleeping quarters were occupied by three or four females and a couple of the recently hatched young, beside Sola and her youthful ward, myself, and Woola the hound. After they had retired for the night it was customary for the adults to carry on a desultory conversation for a short time before lapsing into sleep, and now that I could understand their language I was always a keen listener, although I never proffered any remarks myself. [/item] [item title="C Plus Plus"]At this time our sleeping quarters were occupied by three or four females and a couple of the recently hatched young, beside Sola and her youthful ward, myself, and Woola the hound. After they had retired for the night it was customary for the adults to carry on a desultory conversation for a short time before lapsing into sleep, and now that I could understand their language I was always a keen listener, although I never proffered any remarks myself. [/item] [item title="java programming"]At this time our sleeping quarters were occupied by three or four females and a couple of the recently hatched young, beside Sola and her youthful ward, myself, and Woola the hound. After they had retired for the night it was customary for the adults to carry on a desultory conversation for a short time before lapsing into sleep, and now that I could understand their language I was always a keen listener, although I never proffered any remarks myself. [/item] [item title="web development"]At this time our sleeping quarters were occupied by three or four females and a couple of the recently hatched young, beside Sola and her youthful ward, myself, and Woola the hound. After they had retired for the night it was customary for the adults to carry on a desultory conversation for a short time before lapsing into sleep, and now that I could understand their language I was always a keen listener, although I never proffered any remarks myself. [/item] [/accordion]




[alert title="C Programming Update" icon="info-circle"] This alert needs your attention [/alert] [review]
[item review-value="8"]Hardware[/item]
[item review-value="7"]Gameplay[/item]
[item review-value="6"]Graphics[/item]
[item review-value="9"]Sound[/item]
[content title="Summary" label="Overall Score"]My fellow Earthicans, as I have explained in my book Earth in the Balance, and the much more popular Harry Potter and the Balance of Earth, we need to defend our planet against pollution. Also dark wizards but I know you in the future back in our hands.[/content]
[/review] CODE BOX IS HERE img here
 * C program to create a linked list and display the elements in the list */
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
void main()
{
    struct node
    {
        int num;
        struct node *ptr;
    };
    typedef struct node NODE;
    NODE *head, *first, *temp = 0;
    int count = 0;
    int choice = 1;
    first = 0;
    while (choice)
    {
        head  = (NODE *)malloc(sizeof(NODE));
        printf("Enter the data item\n");
        scanf("%d", &head-> num);
        if (first != 0)
        {
            temp->ptr = head;
            temp = head;
        }
        else
        {
            first = temp = head;
        }
        fflush(stdin);
        printf("Do you want to continue(Type 0 or 1)?\n");
        scanf("%d", &choice);
    }
    temp->ptr = 0;
    /*  reset temp to the beginning */
    temp = first;
    printf("\n status of the linked list is\n");
    while (temp != 0)
    {
        printf("%d=>", temp->num);
        count++;
        temp = temp -> ptr;
    }
    printf("NULL\n");
    printf("No. of nodes in the list = %d\n", count);
}

vhgfhhgfgfdfg hggfd gfhg
int x , y , z ;
float p, q ;
char r, s ;

  1. Coffee
  2. Tea
  3. Milk
    1. Coffee
    2. Tea
    3. Milk

Introduction to C Programming

This article is about Introduction to C Programming.

C programming language is firstly Introduced by Dennis Ritchie in 1972 at AT & T's Bells Laboratory. C Programming Language is high-level, machine independent language. To assure that the C Programming language remain standard, in 1983, American National Standard Institute (ANSI) appointed a technical committee to define a standard for C programming. The first version of C approved in 1989 known as ANSI C. It was then approved by the International Standards Organization (ISO) in 1990. And the version approved by ISO is known as C89.

Historical Development of C Programming

With the knock of 1960 a race for computer languages started. Different languages are invented for different-different purposes like COBOL, FORTRAN, pascal, etc. Later in 1963 Cambridge University came up with a new programming language CPL(Combined Programming language), but it was hard to learn and implement and all these languages were specific for different purposes and none of them is powerful enough to create heavy software's or O.S, they lack the networking functionality (i.e- they don't provide networking facilities like modern programming languages).

In 1967, Martin Richard at Cambridge University itself developed Basic CPL (BCPL). Again it was to specific and very less powerful.

So Ken Thompson took up the charge & come up with B Language, Which was developed AT & T's Bell Laboratory. Unfortunately it was also proved to be specific.

Now the founder of C Programming Language (Dennis Ritchie) took the charge to develop a new language as he fell difficulties in developing UNIX (Operating System). Dennis Ritchie combined the features of both B and BCPL, and lots of new features added to make a new powerful programming language, he named his programming language as ' ' Programming (Since it was successor of B).

Concept of Data-Type was previously not available in any programming language but in c programming language Dennis Ritchie added the Data-Type's.

Being developed along with Unix, C Programming was closely related to Unix. It became popular within a short span of time & became one of the most powerful programming language. C Programming Language is one of the Most powerful programming language today also.

Why we should learn C programming language ?

Why C is so Important to learn as a beginner? Is one of the most asked question by amature programmer. In this section we will mention some points which helps you to analyse the Importance of C-
  • C is an Operating System Language (one of the common language used to develop OS)
  • Majority of programming languages is derived from C itself, For Example-Java, C++, Etc
  • Knowing C will help you to understand the entire family of programming
  • C Programming provides portability (don't need to focus on Computer Architecture while programming)
  • For Example C programs can be compiled and run on the ARM processor as well as on Intel processor too
  • C is a combination of assembly and high level programming language
  • Rich set of library files
  • Numerous inbuilt functions
  • It is one of the most stable and mature language
  • One of the most powerful reason is memory allocation. Unlike other programming language C Provides the access to programmer to directly write to memory
  • Key Features are Struct, Pointers, arrays, Dynamic Memory Allocation(calloc and malloc).
  • Variety of data types available
  • Incrementing a variable from 0 to 15000 would take around 1 second while other interpreter like BASIC would take 50 second
  • C is well suited for Structured Programming, thus requiring the user to think of a problem in terms of function modules or blocks
  • There are only 32 keyword in ANSI C, therefore it's strength lies in built in function's
  • Programs that are written in C are more efficient and fast than other programming language (like java or any other programming language that run on some virtual environment)
  • The modular structure of C programs make it easy to debug, testing and compilation
  • Another important feature of C is its ability to extend itself. For Example- we can use functions that are supported by the C library.
  • We can continuously add our own function to C library

Basic Structure of  program

here


Sample C program and its working

#include <stdio.h>
int main()
{
int a=5,b=7,c;
c=a+b;
printf("Sum of a and b is %d",c);
return 0;
}

Working of above C Program line by line-
  1. Here #include is the preprocessor used to include the header file "stdio.h" and its syntax is #include<headerfilename.h>
  2.  int main()- here int is the return type of main function i.e main() is a function which tells  the compiler that start execution from here. There are some various other forms also. For Example-
    • main()- Default return type is void i.e, it doesn't return any thing,
    • int main()- Return Type is int and it's mandatory to write return 0, at the end of program
    • void main()- Return Type is void i.e, it doesn't return any value,
    • main(void)- This mean's that main function doesn't have any argument,
    • void main(void)- It doesn't return any value and it don't have any argument
    • int main(void)- It return int value to Operating System and doesn't have any argument.
  3. {- This symbol shows the starting scope of main function
  4. int a=5,b=7,c; - here int is the data type of variable a,b and c that are holding values 5 and 7, whereas semicolon ( ; ) states that statement is ended here
  5. c=a+b; - In C Program always execute from right to left i.e- value of b is added with a and assign to c with the help of equal-to operator (=)
  6. printf("Sum of a and b is %d",c); - Here printf() is a inbuilt function to print strings on console we will discuss this in details in later sections. Here %d is a format specifier this will also be discussed in later section
  7. return 0; - This statement is used to return values to Operating System, return 0 means true and mainly used as a syntax.
  8. } - Closing Scope of main () function.
Note- we will Discuss Sample Programs in details in another post

In this article we will discuss about how to install C and how to Compile and Run C program

To write C Programs we need to Install C first, for that we need to setup an environment.
First of all we need a compiler to compile the C programs so for that we can use various available compiler in market, for student's we recommend you to use Turbo C and if you are professional you can use Visual Studio, Dev C, Eclipse C Compiler and many others. All of these compiler works for both C and C++. In this article we will tell teach you how to install turbo C.

[alert title="Note" icon="info-circle"] This Post is for installing C on windows only not on linux or mac stay tuned we will update this post[/alert]

Steps to install turbo c.

  1. Download Turbo C from here -----> Turbo c
  2. After downloading Turbo C locate download folder.
  3. Now double click on it to install.
  4. Permit it then click on next > select terms and condition, then press next
  5. Then again click on next.
  6. Now it will ask to about the directory where you want to install Turbo C, by default it will select ---> C:\TurboC++ (Minimum memory required is 14.2 MB)
  7. If you don't want to install in default directory then you can browse from there and then click install.
  8. Now it is installed.
run c program
turbo c default screen

Compiling and Running C programs

  1. To compile and run c program you need to save file with .c extension.
  2. For saving you need to press f2.
  3. After saving file you have to compile c program for that either you click on compile>compile in top most menu (see pictures).
  4. Shortcut to compile c program is alt+f9.
  5. Now to run programs you need to click on run > run or press ctrl+f9.

C Constants and Variables
C Constants-

Constant are those who never change their values throughout the program. They are declared in a manner that they are assigned to some variable whose values get fixed and thus become constant.For Example- 1 , 2.5 , 'C' , "Constant". Here all these are constant.

Types of C constant-

  • Primary Constant-Primary constant are again divided into 4 categories-Integer, Real, Character Constant.
  • Secondary Constant-Secondary constant is categorized 5 parts and they are- Array, Pointer, Structure, Union, Enum etc.

Integer Constant-

Integer Constant refer to a sequence of digits. There are 3 Types of Integer Constant
  • Decimal Integer Constant- Decimal integer consists of a set of digits, 0 to 9, preceded by unary minus sign ( - ) or unary plus sign ( + ). For Example- 123, -123
  • Octal Integer Constant- Octal Integer Constant consists of any combination of digits from 0 to 7, with a preceding 0. For Example- 01996, 078.
  • Hexadecimal Integer Constant- Hexadecimal Integer Constant consists a sequence of digit preceded by 0x or 0X. For example- 0x5, 0X5.

Rules For Naming Integer Constant in C-

  • An integer constant have at least 1 number. For Example- 1, 2, 23, 4567, 11511565.
  • Integer Constant must not have any decimal point. For Example- 5.4.
  • It Could be positive or negative.
  • In case of negative number it's compulsory to use unary minus sign( - ). For Example: -5.
  • In case of positive integer constant its not mandatory to use unary plus ( + ) sign, however you can use it. For Example- +5 or 5 both are valid.
  • If no sign is assigned then it is assumed to be a positive number. For Example- 5.
  • No commas, blank space, Special symbols are allowed between or with number. For Example- $5, 5$0, 50,000, etc are not allowed.
  • The range of Integer Constant depends on word size of the computer. For 16- bit computer it is -32768 to +32767 and for 32 bit range is 2147483648 to 2147483647.

Real Constant-

Real constant are used to represent quantity like distances, volume, area etc. Real Constant are represented by fractional part like 19.96. Such numbers are called real (or floating point) constant.

Example- 0.123, -0.159, +125.789.

Real Constants can also be represented by exponential notation. For example the value 555.444 is represented by 5.55444e2 in exponential notation.

Mantissa e Exponent

Rules For Naming Real Constant in C-

Real constant are also known as Floating point constant. The real constant could be written in two forms, Fractional form and exponential form.
  • A real Constant must have a deciaml point. For Example- 5.0.
  • It Could be positive or negative
  • In case of negative number it's compulsory to use unary minus sign( - ). For Example: -5.0.
  • In case of positive number its not mandatory to use unary plus ( + ) sign, however you can use it. For Example- +5.0 or 5.0 both are valid.
  • If no sign is assigned then it is assumed to be a positive number. For Example- 5.
  • No commas, blank space, Special symbols are allowed between or with number. For Example- $5.0, 5$.0, 50,000.7512, etc are not allowed.
  • The exponential form of representation of real constant is usually used if the value of constant is either too small or too large.
  • For exponential representation mantissa and exponential part should be separated by a single letter ( e ). For Example- 3.2e5.
  • Mantissa part may have positive or negative sign.
  • The exponential part may have at least one digit.

Rules For Naming Character Constant in C-

  • A character constant is a single character (character can be alphabet, digit, symbols, etc) enclosed withing single quotation mark ('C').
  • Maximum character enclosed within quotation mark is one (1). If more than one character is written withing single Quotation mark then compiler shows an error. For Example- 'abc'.

C Variables-

Variable is just like a container to store a value, Every constant value is assigned to some variable.
Variable are declared in the beginning of the main function or any other function.

Basic Structure of C Programs
Creating or Coding Program-

To write a program you first need to analyze the problem to which your program will provide the solution. Once this analysis is complete you have to identify the data involved in it and then develop an algorithm, which is further converted into flowchart.
This flowchart is rewritten in C-Language following the syntaxes and the rules & conventions of C-Compiler you are working with. Different compilers may need to alter your program codes due to different facilities provided by them . e.g. The built in functions may vary compiler-to-compiler, sufficient enough to make your programs different to each other.

Basic Structure of C Program-

C program is considered as collections of small units called functions. A function is a collection of C statements united together to perform some definition individual task.
C Program Structure-

        Comments or Documentation section
        Linking Section
        Definition Section
        Global Declaration Section
        Main function
        {
                Declaration Section for the main function
                Executable Section (the statements)
        }
                Subprogram of other function definition
         Function 1
        {
                Declaration
                Executable
        }
        Function 2
        {
                Declaration
                Executable
        }

The Comment section-

This Section includes the name of author, date and other details. Compiler does not execute the comment section and this does not affect the speed of program execution. Comments can be included in the program anywhere and this practice is preferred because it improves the readability of program.

The Linking Section-

This section involves the name of header files or functions of system library, which are supposed to be linked with the program code.

Definition Section-

In this Section you can define the symbolic constant with preprocessor directive #define. Once this is defined it can be used later in the program with defined name.

Global Declaration Section-

Few variable are required to be globally declared before main function. Global declaration means that the variable can be used globally anywhere throughout the project.

Main Function-

Every C program has to have a main function. This function tells the compiler that the program begins here. Not more than one main function is allowed in a program, because it may confuse the compiler about the beginning of the program. Main function again contains a declaration part in which the variables and functions are declared which is valid in main function only. To be available outside it, they have to be declared globally. The executable part of main function include the statement, which are executed to generate output etc.

Subprogram Section-

This section is identical to main function as they are definition of functions, which are referenced, in main function. These are user-defined functions.

Compiling and linking section

Once this part of your program development is complete it is considered as a source program. The source program is then input to C compiler for compilation. This C compiler has its own pre-processor which understands the pre-processor directives of the source code. These preprocessor directive tells the compiler how to process the source code, with these specification the source code is inverted into an object code which has same name of C program  source code but obj as extension and saved in the disk. In object code of program there are no pre processor directives left. The syntax error, if found then error message generated which are used in diagnostic purposes.
        The object code so produced in machine language is then linked with the system library functions, which it refers to. There may be different modules of the project, which may be required to be linked with each other before running the program. So linker performs that task also and finally produces the executable code of the object code.
        This executable code is saved out to the disk with .exe extension, which is also called exe file or run file of the program.

Testing and Debugging-

The program is checked for syntax errors while compilation and corrected simultaneously. Once the program is compiled and executed it's output is checked, whether it matches with Specification and desired output. This testing is done at different levels and for different possible errors, by feeding data into it. If errors is found then it is corrected and the program is again tested. This is testing methodology is called Retesting and correction and removing errors called bugs is called debugging. Once the program is found satisfying the specifications bug  free it is ready for implementation.

C Data Types
Data type is used to define the type of variable that we declare at the beginning of the program.
The output of a C program depends upon the processing it does on the data fed, thus the better you are able to classify data, better and more precise results are expected. C has the capability to classify the data into more specific arrangements.
C supports the following basic data types-

  1. Primary data type
  2. Secondary data type
  3. Enumerated data type
  4. Void data type
  5. User defined data type

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget